import { Body, Get, Inject, Post, Query } from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { OrderCartService } from '../../service/cart';
import { OrderCartEntity } from '../../entity/cart';
/**
 * 购物车
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: OrderCartEntity,
  service: OrderCartService,
})
export class AppOrderCartController extends BaseController {
  @Inject()
  orderCartService: OrderCartService;
  
  @Inject()
  ctx;
  /**
   * 添加到购物车
   */
  @Post('/addCart')
  async addCart(@Body() body: {
    goodsId: string;
    count?: number;
  }) {
    return this.ok(await this.orderCartService.addCart(this.ctx.user.erpBusinessId, body.goodsId, body.count));
  }

  /**
   * 更新购物车商品数量
   */
  @Post('/updateCount')
  async updateCount(@Body() body: {
    id: number;
    count: number;
  }) {
    return this.ok(await this.orderCartService.updateCount(this.ctx.user.erpBusinessId, body.id, body.count));
  }

  /**
   * 删除购物车商品
   */
  @Post('/remove')
  async remove(@Body('ids') ids: number[]) {
    return this.ok(await this.orderCartService.remove(this.ctx.user.erpBusinessId, ids));
  }

  /**
   * 清空购物车
   */
  @Post('/clear')
  async clear() {
    return this.ok(await this.orderCartService.clear(this.ctx.user.erpBusinessId));
  }

  /**
   * 购物车列表
   */
  @Get('/listCart')
  async listCart() {
    return this.ok(await this.orderCartService.listCart(this.ctx.user.erpBusinessId));
  }
} 